package POJO;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "CATEGORY", uniqueConstraints = {
		@UniqueConstraint(columnNames = "Category_Id"),
		@UniqueConstraint(columnNames = "Category_Name"),
		@UniqueConstraint(columnNames = "Parent_Id")
})
public class Category implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1786703487431537452L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "Category_Id")
	private int categoryId;
	
	@Column(name = "Category_Name")
	private String categoryName;
	
	@Column(name = "Tag")
	private String tag;
	
	@Column(name  = "Priority")
	private int priority;
	
	@Column(name = "Description")
	private String description;
	
	@Column(name = "Status")
	private String status;
	
	@Column(name = "Parent_Id")
	private int parentId;
	
	@ManyToMany( cascade = {CascadeType.MERGE, CascadeType.PERSIST},  fetch = FetchType.EAGER)
	@JoinTable(name = "CATEGORY_IMAGE", joinColumns = {
			@JoinColumn(name = "Category_Id", nullable = false, updatable = true, insertable=true)},
			inverseJoinColumns = { @JoinColumn(name = "Image_Id", 
												nullable = false, updatable = true, insertable=true)})
	private Set<Image> images;
	
	@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
	@JoinTable(name = "PRODUCT_CATEGORY", joinColumns = {
			@JoinColumn(name = "Category_Id", nullable = false, updatable = true, insertable=true)},
			inverseJoinColumns = { @JoinColumn(name = "Product_Id", 
												nullable = false, updatable = true, insertable=true)})
	private Set<Product> products;
	
	public Category() {
		super();
	}

	public Category(String categoryName, int parentId) {
		super();
		this.categoryName = categoryName;
		this.parentId = parentId;
	}

	public Category(String categoryName, int parentId, String tag,
			int priority, String description, String status) {
		super();
		this.categoryName = categoryName;
		this.parentId = parentId;
		this.tag = tag;
		this.priority = priority;
		this.description = description;
		this.status = status;
	}
	
	public Category(String categoryName, int level, int parentId,
			Set<Image> images) {
		super();
		this.categoryName = categoryName;
		this.priority = level;
		this.parentId = parentId;
		this.images = images;
	}
	
	public Category(String categoryName, int level, int parentId,
			Set<Image> images, Set<Product> p) {
		super();
		this.categoryName = categoryName;
		this.priority = level;
		this.parentId = parentId;
		this.images = images;
		this.products = p;
	}

	public Category(String categoryName, String tag, int priority,
			String description, String status, int parentId, Set<Image> images) {
		super();
		this.categoryName = categoryName;
		this.tag = tag;
		this.priority = priority;
		this.description = description;
		this.status = status;
		this.parentId = parentId;
		this.images = images;
	}

	public Category(String categoryName, String tag, int priority,
			String description, String status, int parentId, Set<Image> images,
			Set<Product> products) {
		super();
		this.categoryName = categoryName;
		this.tag = tag;
		this.priority = priority;
		this.description = description;
		this.status = status;
		this.parentId = parentId;
		this.images = images;
		this.products = products;
	}

	public Category(String categoryName, String tag, int priority,
			String description, String status, Set<Image> images) {
		super();
		this.categoryName = categoryName;
		this.tag = tag;
		this.priority = priority;
		this.description = description;
		this.status = status;
		this.images = images;
	}

	public Category(String categoryName, String tag, int priority,
			String description, String status, Set<Image> images,
			Set<Product> products) {
		super();
		this.categoryName = categoryName;
		this.tag = tag;
		this.priority = priority;
		this.description = description;
		this.status = status;
		this.images = images;
		this.products = products;
	}

	public int getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public int getParentId() {
		return parentId;
	}

	public void setParentId(int parentId) {
		this.parentId = parentId;
	}

	public Set<Image> getImages() {
		return images;
	}

	public void setImages(Set<Image> images) {
		this.images = images;
	}

	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}
	
	
	
	
}
